package com.jmuok.web.fff.web;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.security.authentication.encoding.PasswordEncoder;

import com.jmuok.web.fff.util.ApplicationHelper;
import com.jmuok.web.fff.web.ui.UserRegForm;
import com.jmuok.web.fff.web.ui.UserRegView;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Window;


public class UserRegWindow extends Window {
	private static final long serialVersionUID = -4862569012848193459L;
	private ApplicationHelper helper = ApplicationHelper.instance();

	
	@SuppressWarnings("serial")
	public UserRegWindow() {
		setCaption(helper.getMessage("signup.title"));
		this.setModal(true);
		this.setSizeUndefined();
		this.setResizable(false);
		setWidth("450px");

		final UserRegView userView = new UserRegView();
		userView.getTableContainer();
		userView.createNewEntity();

		// Item item = userView.getItemForEntity(new User());

		UserRegForm userForm = userView.getUserRegForm();

		// getForm().setFormFieldFactory(getFormFieldFactory());

		// userForm.setItemDataSource(item);
		userForm.addSaveActionListener(new ClickListener() {

			@Override
			public void buttonClick(ClickEvent event) {
				if (userView.doCommit()) {
					getApplication().getMainWindow().showNotification(helper.getMessage("icon.information"),
							helper.getMessage("user.registered"));
					close();
				}

			}
		});
		userForm.addCancelActionListener(new ClickListener() {

			@Override
			public void buttonClick(ClickEvent event) {
				close();
			}
		});
		// userForm.setHeight("400px");
		userForm.setParent(null);
		setContent(userForm);

	}

}
